package com.bjwen;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.lang.reflect.*;

public class Main {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> fftType = Class.forName("com.bjwen.FFt");
        Constructor<?> constructor = fftType.getDeclaredConstructor(List.class);
        FFt fft = (FFt) constructor.newInstance(scanIn());
        printOut(fft.proceed());
    }

    private static List<Double> toList(String s) {
        String[] strings = s.split(" ");
        List<Double> list = new ArrayList<>(strings.length);
        for (String string : strings) {
            list.add(Double.parseDouble(string));
        }
        return list;
    }

    private static void printOut(Complex[] list) {
        for (Complex complex : list) {
            System.out.println(complex);
        }
    }

    private static List<Double> scanIn() {
        Scanner scanner = new Scanner(System.in);
        Instructions ins = new Instructions();
        System.out.println(ins.getGreeting());
        List<Double> list;
        for (; ; ) {
            String s = scanner.nextLine();
            //String s="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16";
            if (s.length() == 0) {
                System.out.println(ins.getErrorInput());
                continue;
            }

            list = toList(s);
            if (isValidSize(list.size())) break;
            else System.out.println(ins.getErrorInput());
        }
        return list;
    }

    private static boolean isValidSize(int size) {
        if (size == 1 || size == 0) return false;
        while (size != 1) {
            if (size % 2 != 0) return false;
            size /= 2;
        }
        return true;
    }
}
